﻿namespace Jsl.FxCop
{
    using System.Collections.Generic;
    using Microsoft.FxCop.Sdk;

    /// <summary>
    /// Holds statement flow information about one statement.
    /// </summary>
    public class StatementInfo
    {
        private readonly List<Statement> following = new List<Statement>();
        private readonly List<Statement> previous = new List<Statement>();
        private readonly Statement statement;

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="StatementInfo"/> class.
        /// </summary>
        /// <param name="statement">The statement.</param>
        public StatementInfo(Statement statement)
        {
            this.statement = statement;
        }
        #endregion Constructors

        #region Public Properties
        /// <summary>
        /// Gets the following statements.
        /// </summary>
        /// <value>The following statements.</value>
        public IEnumerable<Statement> Following
        {
            get { return this.following; }
        }

        /// <summary>
        /// Gets the previous statements.
        /// </summary>
        /// <value>The previous statements.</value>
        public IEnumerable<Statement> Previous
        {
            get { return this.previous; }
        }

        /// <summary>
        /// Gets the statement.
        /// </summary>
        /// <value>The statement.</value>
        public Statement Statement
        {
            get { return this.statement; }
        }
        #endregion Public Properties

        #region Internal Methods
        /// <summary>
        /// Adds the statement to the collection of following statements.
        /// </summary>
        /// <param name="followingStatement">The statement that follows our statement.</param>
        internal void AddFollowing(Statement followingStatement)
        {
            if (!this.following.Contains(followingStatement))
            {
                this.following.Add(followingStatement);
            }
        }

        /// <summary>
        /// Adds the statement to the collection of previous statements.
        /// </summary>
        /// <param name="previousStatement">The statement that is before our statement.</param>
        internal void AddPrevious(Statement previousStatement)
        {
            if (!this.previous.Contains(previousStatement))
            {
                this.previous.Add(previousStatement);
            }
        }
        #endregion Internal Methods
    }
}